<?php include_once './application/views/sys_admin/common/header.php';  ?>
<script>
function changeRule(_this){
	var id = $(_this).attr("dataid");
	if(id>0){
		$( "#dialog" ).dialog({
			height:450,
			width:500,
			modal:true, //蒙层（弹出会影响页面大小）
			title:'编辑代金券规则'
		});
		$("#id").val(id);
		$("#title").val($(_this).attr("adata"));
		$("#money").val($(_this).attr("bdata"));
		$("#start_time").val($(_this).attr("cdata"));
		$("#end_time").val($(_this).attr("ddata"));
		if($(_this).attr("edata") == 0){
			$("input[type=radio][value=0]").attr("checked",'checked');
		}else{
			$("input[type=radio][value=1]").attr("checked",'checked');
		}
		
	}
}

function submitRule(){
	var id = $("#id").val();
	var status = $("input[name='fstatus']:checked").val();
	if(id > 0){
		$.ajax({
			type: "POST",
			url: "/sys_admin/redmanagement/red_save",
			data: "act=edit&id="+id+"&title="+$("#title").val()+"&money="+$("#money").val()+"&start_time="+$("#start_time").val()+"&end_time="+$("#end_time").val()+"&fstatus="+status,
			success: function(ret){
				$("#dialog" ).dialog();
				$("#msg").html(ret.msg);
				setTimeout(function(){
					$("#dialog" ).dialog("close");
				},3000);
				window.location.reload();
			},
			dataType: "json"
		});	
	}
}
</script>
<div id="dialog" title="系统提示" style="display:none;">
<div id="msg" style="text-align:center;color:red">&nbsp;</div>
<input type="hidden" name="id" id="id" />

	<table class="table table-bordered table-hover m10">
		 <tr>
	        <td class="tableleft">代金券类型 </td>
	        <td><input type="text" name="title" id="title" />   </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft">代金券金额 </td>
	        <td><input type="text" name="money" id="money" />  </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft">起始时间 </td>
	        <td><input type="text" name="start_time" id="start_time" onfocus="WdatePicker()" class="Wdate" />   </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft">截至时间</td>
	        <td><input type="text" name="end_time" id="end_time" onfocus="WdatePicker()" class="Wdate"  />   </td>
	   	</tr>
	   	<tr>
	        <td class="tableleft">状态</td>
	        <td><input type="radio" name="fstatus" id="fstatus" value="0" />关闭<input type="radio" name="fstatus" id="fstatus" value="1" />开启 </td>
	   	</tr>
	</table>   	
	<div style="text-align:center;">
	<input type="button" style="width: 60px; height:24px" value="关闭" onclick="$('#dialog').dialog('close');"/>
	<input type="button" style="width: 60px; height:24px" value="修改" onclick="submitRule();" />
	</div>
</div>
<div class=" definewidth m20">
		<form  class="form-inline definewidth m20">
		<button type="button" class="btn btn-success"  onclick="href('/sys_admin/systemset/addparameter');" >添加</button>
	  	</form>
		<table class="table table-bordered table-hover definewidth m10">
			 <thead>
			    <tr>
			       <td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>序号</strong></td>
					<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>代金券类型</strong></td>
					<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>代金券金额</strong></td>
					<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>起始时间</strong></td>
					<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>截止时间</strong></td>
					<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>状态</strong></td>
					<td height="35" align="center" valign="middle" bgcolor="#F1F1F1"><strong>操作</strong></td>
			    </tr>
			   </thead>
			<?php if($list){foreach ($list as $v){?>
		  	<tr>
			<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['id'];?></td>
			<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['title'];?></td>
			<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['money'];?></td>
			<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo date('Y-m-d',$v['start_time']);?></td>
			<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo date('Y-m-d',$v['end_time']);?></td>
			<td height="35" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $v['fstatus']==0?"关闭":"开启";?></td>
			<td height="35" align="center" valign="middle" bgcolor="#FFFFFF">
			<a 	dataid="<?php echo $v['id'];?>" 
				adata="<?php echo $v['title'];?>" 
				bdata="<?php echo $v['money'];?>" 
				cdata="<?php echo date('Y-m-d',$v['start_time']);?>" 
				ddata="<?php echo date('Y-m-d',$v['end_time']);?>" 
				edata="<?php echo $v['fstatus'];?>" onclick="changeRule(this);" href="javascript:;">编辑</a></td>
		  	</tr>	
		  <?php }}?>
			  	<tr>
			  	<td colspan="12"  class="invbd_page"><?php echo $this->pagination->create_links();?></td>
			  	</tr>
		</table>
</div>
